Imports System.IO

Partial Class EditSquad
    Inherits System.Web.UI.Page

    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Sub FileUploaded(ByVal sender As Object, ByVal e As PictureUpload.FileUploadEventArgs)

        Dim boundControl As TextBox = CType(DetailsView1.FindControl("TextBox1"), TextBox)
        boundControl.Text = e.FileName

    End Sub

    Sub DetailsDataSource_Updated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)

        GridView1.DataBind()

    End Sub

    Sub DetailsDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)

        GridView1.DataBind()

    End Sub

    Protected Sub DetailsDataSource_Deleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles DetailsDataSource.Deleting

        Dim today As DateTime = DateTime.Now()
        Dim startYear As Integer
        Dim endYear As Integer
        Dim seasonStart As DateTime
        Dim seasonEnd As DateTime

        If today.Month > 5 Then
            ' if the current date is after may then the 
            ' season runs from August until next May
            startYear = today.Year
            endYear = today.Year + 1
        Else
            ' if the current date is before May then the 
            ' season runs from last August to this may
            startYear = today.Year - 1
            endYear = today.Year
        End If

        seasonStart = New DateTime(startYear, 8, 20)    ' 20th August
        seasonEnd = New DateTime(endYear, 5, 31)        ' 31 May

        If today >= seasonStart And today <= seasonEnd Then
            e.Cancel = True
            Status.Text = "Cannot delete players during the season"
        Else
            Status.Text = ""
        End If

    End Sub
End Class
